package com.kingwood.algorithm.test;

import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: TODO
 * 掌握的单词个数
 * https://fcqian.blog.csdn.net/article/details/134642497
 *
 * @Date: 2024/2/27 16:20
 * @Modified By：
 * @Version 1.0
 */
public class WordCount {
    public static int getWordCount(String[] words, int n, String chars) {
        int ans = 0;
        int[] cnt_chars = charStatistic(chars);

        for (int i = 0; i < n; i++) {
            String word = words[i];
            int[] cnt_word = charStatistic(word);
            int diff  = 0;

            for (int j = 0; j < 128; j++) {
                diff += Math.max(cnt_word[j] - cnt_chars[j], 0);
            }

            if (diff <= cnt_chars['?']) {
                ans++;
            }
        }

        return ans;
    }

    public static int[] charStatistic(String chars) {
        int[] cnts = new int[128];
        for (int i = 0; i < chars.length(); i++) {
            char c = chars.charAt(i);
            cnts[c] += 1;
        }

        return cnts;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] words = new String[n];
        for (int i = 0; i < n; i++) {
            words[i] = scanner.next();
        }

        String chars = scanner.next();
        System.out.println(getWordCount(words, n, chars));
    }
}
